package com.yuan.mint.adapter;

import android.content.Context;
import android.net.Uri;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.yuan.mint.R;
import com.yuan.mint.bean.DietPostsBean;
import com.yuan.mint.utils.MintUtils;
import com.yuan.mint.widget.RoundImageView;

import java.util.List;

public class RecommendDetailAdapter extends AppBaseAdapter<DietPostsBean> {

    private DisplayImageOptions displayImageOptions;

    public RecommendDetailAdapter(List<DietPostsBean> list, Context context) {
        super(list, context);
        displayImageOptions = MintUtils.getDisplayImageLoader();
    }

    @Override
    public ViewHolder getViewHolder(int position, View convertView, ViewGroup parent) {
        DietPostsBean post = list.get(position);
        ViewHolder vh = ViewHolder.get(context,convertView,parent, R.layout.diet_item);
        RoundImageView img = (RoundImageView) vh.findViewById(R.id.head_img);
        TextView username = (TextView) vh.findViewById(R.id.username);
        TextView time = (TextView) vh.findViewById(R.id.share_time);
        TextView content = (TextView) vh.findViewById(R.id.share_content);

        ImageLoader.getInstance().displayImage(post.getUser().getAvatar_url(), img, displayImageOptions);
        img.setImageURI(Uri.parse(post.getUser().getAvatar_url()));
        username.setText(post.getUser().getNickname());
        String date = post.getCreated_at();
        time.setText(date.substring(5,10) +"  " + date.substring(11,16));
        content.setText(post.getBody());
        return vh;
    }
}
